package com.geekaca.d4.d3;

import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;

public class TestFormater {
    public static void main(String[] args) {
        /**
         *  SimpleDateFormate Date 组合
         *  DateTimeFormatter 格栻化 LocalDateTime;
         */
        LocalDateTime nowDateTime = LocalDateTime.now();
        System.out.println("LocalDateTime.now() = " + LocalDateTime.now());
        DateTimeFormatter dtf = DateTimeFormatter.ofPattern("yyy-MM-dd HH:mm:ss");
        String format = dtf.format(nowDateTime);
        System.out.println(format);

        //只要年
        DateTimeFormatter dtf2 = DateTimeFormatter.ofPattern("yyyy年");
        String formatYear = dtf2.format(LocalDateTime.now());
        System.out.println(formatYear);

        //String->LocalDateTime;
        DateTimeFormatter dt3 = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
        LocalDateTime parsedDateTime = LocalDateTime.parse("2003-12-25 12:00:00", dt3);
        System.out.println(parsedDateTime);
    }
}
